<template>
    <view class="content">
        <view class="item" v-for="(item, index) in list" :key="index">
            <view class="info">
                <view class="item-info">
                    <image :src="IMAGEURL + 'static/icon/icon_01.png'" class="icon-01"></image>
                    <view class="name">{{item.name}}</view>
                    <view class="male" v-if="item.gender == 1">男</view>
                    <view class="female" v-if="item.gender == 2">女</view>
                    <view class="age">{{item.age}}岁</view>
                </view>
                <!-- status：1未报销 2已报销 -->
                <view class="pay" v-if="item.status == 1">未支付</view>
                <view class="pay pay2" v-else>已支付</view>
            </view>
            <view class="u-p-t-35">
                <view class="parent">
                    <view class="parent-l">
                        <image :src="item.image" class="avatar"></image>
                        <view class="u-flex-1">{{item.user_name}}</view>
                    </view>
                    <view class="time">{{item.date}}</view>
                </view>
                <view class="u-p-t-20">
                    <view class="down" v-if="item.images.length > 0">
                        <view>图片：</view>
                        <view class="img-box">
                            <image :src="el.image" class="img" v-for="(el, ind) in item.images" :key="ind" @click="doPreview(item.images, ind)"></image>
                        </view>
                    </view>
                    <view class="down">
                        <view>报销金额：</view>
                        <view class="price">￥{{item.money}}</view>
                    </view>
                    <view class="down">
                        <view>报销描述：</view>
                        <view class="text">{{item.describes}}</view>
                    </view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="footer" @click="$gTo(`/serve/pages/fw-bx/fw-bx-create`)">创建</view>
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                IMAGEURL,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            //预览照片
            doPreview(item, index) {
                let arr = []
                item.forEach(cur => {
                    arr.push(cur.image)
                })
                uni.previewImage({
                    urls: arr,
                    current: index,
                    longPressActions: {
                        success: function(data) {
                        },
                        fail: function(err) {
                        }
                    }
                });
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('reimbursement', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    type: 2,//1用户端 2服务端
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.reimbursement && ret.detail.reimbursement.length > 0) {
            				this.list = this.list.concat(ret.detail.reimbursement);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx 20rpx 100rpx;
    }
    .item{
        padding: 35rpx 25rpx;
        margin-bottom: 20rpx;
        background-color: #fff;
        border-radius: 15rpx;
    }
    .info{
        padding-bottom: 35rpx;
        border-bottom: 2rpx solid #e6e6e6;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .pay{
        font-size: 24rpx;
        color: #f62a2a;
        padding-left: 15rpx;
    }
    .pay2{
        color: #727272;
    }
    .item-info{
        flex: 1;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .icon-01{
        width: 37rpx;
        height: 37rpx;
        margin-right: 15rpx;
    }
    .name{
        font-size: 32rpx;
        font-weight: bold;
        padding-right: 15rpx;
    }
    .male{
        width: 34rpx;
        height: 34rpx;
        border-radius: 5rpx;
        background-color: #edf6ff;
        font-size: 26rpx;
        color: #2d96fa;
        text-align: center;
        line-height: 34rpx;
    }
    .female{
        width: 34rpx;
        height: 34rpx;
        border-radius: 5rpx;
        background-color: #ffeeed;
        font-size: 26rpx;
        color: #ff5748;
        text-align: center;
        line-height: 34rpx;
    }
    .age{
        font-size: 26rpx;
        color: #727272;
        padding-left: 15rpx;
    }
    
    .parent{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .parent-l{
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 32rpx;
        font-weight: bold;
    }
    .avatar{
        width: 50rpx;
        height: 50rpx;
        border-radius: 15rpx;
        margin-right: 12rpx;
    }
    .time{
        font-size: 24rpx;
        color: #555558;
        font-weight: normal;
    }
    
    .down{
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        padding-top: 10rpx;
        font-size: 24rpx;
    }
    .img-box{
        flex: 1;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .img{
        width: 130rpx;
        height: 130rpx;
        border-radius: 10rpx;
        margin-right: 10rpx;
    }
    .price{
        font-size: 28rpx;
        color: #f62a2a;
    }
    .text{
        flex: 1;
        white-space: pre-line;
        word-break: break-all;
    }
    
    .footer{
        width: 100vw;
        height: 92rpx;
        background-color: #f29700;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        line-height: 92rpx;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 9;
    }

</style>
